var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    id:'',
    info:{},
    belong_canteen:''
  },
  tel_phone:function(){
    wx.makePhoneCall({
      phoneNumber: this.data.info.phone
    })
  },
  // 暂停员工
  pauseTap:function(e){
    var that = this;
    wx.request({
      url: app.globalData.url + 'api/Client/SuspendNumber',
      method: "POST",
      data: {
        openid: app.globalData.openid,
        id: that.data.id,
        status: that.data.info.info.status
      },
      success: function (res) {
        wx.showToast({
          title: '已暂停',
          duration: 300,
          success: function (res) {
            console.log(res.data);
            var ids = that.data.belong_canteen;
            wx.redirectTo({
              url: '../yuangongguanli?id=' + ids,
            })
          }
        })
      }
    });
  },
  // 设置主管
  change_zhuguan:function(){
    var that = this;
    var info=that.data.info;
    var charge_id;
    if(info.is_charge==1){
      charge_id=0;
      info.is_charge=0;
    }else if(info.is_charge==0){
      charge_id=info.id;
      info.is_charge=1;
    }
    app.AppHttp('api/Client/setCharge', {
      charge_id:charge_id,
      id:that.data.info.part_id
    }, function (res) {
      console.log(JSON.stringify(res.data));
      that.setData({
        info:info
      });
      wx.showToast({
        title: res.data.msg,
      }); 
    });
  },
  delTap:function(){
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确定删除该员工？',
      success: function (sm) {
        if (sm.confirm) {
          wx.request({
            url: app.globalData.url + 'api/Client/DelEmployee',
            method: "POST",
            data: {
              openid: app.globalData.openid,
              id: that.data.id
            },
            success: function (res) {
              console.log(JSON.stringify(res.data));
              wx.showToast({
                title: res.data.msg,
                duration: 300,
                success: function (res) {
                  var ids = that.data.belong_canteen;
                  wx.redirectTo({
                    url: '../yuangongguanli?id=' + ids,
                  })
                }
              })
            }
          });
        }else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    });  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id1 = options.id;
    console.log(options);
    this.setData({
      id:id1,
      nick_name:options.nick_name
    });
    var that = this;
    wx.request({
      url: app.globalData.url + 'api/Client/SetEmployee' ,
      method: "POST",
      data: {
        openid: app.globalData.openid,
        id: that.data.id,
      },
      success: function (res) {
       console.log(JSON.stringify(res.data));
       that.setData({
         info:res.data,
         belong_canteen: res.data.belong_canteen
       })
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})